﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace DarazSdk.Models.Request
{

    /// <summary>
    /// 请求
    /// </summary>
    [XmlType(TypeName = "Product")]
    public class ProductRequest
    {
        /// <summary>
        /// 
        /// </summary>
        public int PrimaryCategory { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int SPUId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string AssociatedSku { get; set; } = string.Empty;

        /// <summary>
        /// 
        /// </summary>
        public ProductAttributes Attributes { get; set; } = new ProductAttributes();

        /// <summary>
        /// 
        /// </summary>
        public List<ProductSku> Skus { get; set; } = new List<ProductSku>();

    }

    /// <summary>
    /// 请求属性
    /// </summary>
    public class ProductAttributes
    {
        /// <summary>
        /// Name
        /// </summary>
        [XmlElement("name")]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// short_description
        /// </summary>
        [XmlElement("short_description")]
        public string ShortDescription { get; set; } = string.Empty;

        /// <summary>
        /// brand
        /// </summary>
        [XmlElement("brand")]
        public string Brand { get; set; } = string.Empty;

        /// <summary>
        /// model
        /// </summary>
        [XmlElement("model")]
        public string Model { get; set; } = string.Empty;

        /// <summary>
        /// kid_years
        /// </summary>
        [XmlElement("kid_years")]
        public string KidYears { get; set; } = string.Empty;
    }



    /// <summary>
    /// Skus->Sku
    /// </summary>
    [XmlType("Sku")]
    public class ProductSku
    {
        /// <summary>
        /// 将添加到的Seller Center实例中产品的唯一标识符系统。这个标识符通常是自由分配的。统一标识符，如UPC或EAN 可以通过ProductId设置。强制性的
        /// </summary>
        public string SellerSku { get; set; } = string.Empty;

        /// <summary>
        /// 产品价格 强制性的
        /// </summary>
        [XmlElement("price")]
        public decimal Price { get; set; }

        /// <summary>
        /// 库存
        /// </summary>
        [XmlElement("quantity")]
        public int Quantity { get; set; }

        /// <summary>
        /// 该产品在销售时的(有望降低的)价格。如果指定了special_price， 必须指定special_from_date或special_to_date至少有一个 如果指定了Special_from_date或special_to_date，则special_price是必需的
        /// </summary>
        [XmlElement("special_price")]
        public decimal SpecialPrice { get; set; }

        /// <summary>
        /// special_from_date
        /// </summary>
        [XmlIgnore]
        public DateTime SpecialFromDate { get; set; }


        /// <summary>
        /// special_from_date
        /// </summary>
        [XmlElement("special_from_date")]
        public string Raw_SpecialFromDate
        {
            get { return SpecialFromDate.ToString("yyyy-MM-dd HH:mm:ss"); }
            set { _ = value; }
        }

        /// <summary>
        /// special_to_date
        /// </summary>
        [XmlIgnore]
        public DateTime SpecialToDate { get; set; } = DateTime.Now;

        /// <summary>
        /// special_from_date
        /// </summary>
        [XmlElement("special_to_date")]
        public string Raw_SpecialToDate
        {
            get { return SpecialToDate.ToString("yyyy-MM-dd HH:mm:ss"); }
            set { _ = value; }
        }


        /// <summary>
        /// package_height
        /// </summary>
        [XmlElement("package_height")]
        public string PackageHeight { get; set; } = string.Empty;

        /// <summary>
        /// package_length
        /// </summary>
        [XmlElement("package_length")]
        public string PackageLength { get; set; } = string.Empty;

        /// <summary>
        /// package_weight
        /// </summary>
        [XmlElement("package_width")]
        public string PackageWidth { get; set; } = string.Empty;

        /// <summary>
        /// package_width
        /// </summary>
        [XmlElement("package_weight")]
        public string PackageWeight { get; set; } = string.Empty;

        /// <summary>
        /// package_content
        /// </summary>
        [XmlElement("package_content")]
        public string PackageContent { get; set; } = string.Empty;

        /// <summary>
        /// 包含最多8个图片URL。可选
        /// </summary>
        [XmlArrayItem("Image")]
        public List<string> Images { get; set; } = new List<string>();

        /// <summary>
        /// 图像的URL。一个SKU最多可以设置8张图片。第一个图像
        /// </summary>
        public string Image { get; set; } = string.Empty;
    }
}

